from django.db import models
from constant import ORDER_STATUS_NOT_PAY

# Create your models here.

# 管理员(已完成)
class Admin(models.Model):
    username = models.CharField(max_length=10)
    password = models.CharField(max_length=15)
    ctime = models.DateTimeField(auto_now=True, null=True)


# 用户注册(已完成)
class UserInfo(models.Model):
    username = models.CharField(max_length=32)
    password = models.CharField(max_length=64)
    email = models.CharField(max_length=32, null=True)
    phone = models.CharField(max_length=11, null=True)
    number = models.CharField(max_length=10)
    ctime = models.DateTimeField(auto_now=True, null=True)
    userToken = models.CharField(max_length=100)
    userAddress = models.CharField(max_length=100)



# 用户个人信息((未完成))
class Personage_info(models.Model):
    name = models.CharField(max_length=10)
    address = models.CharField(max_length=10)
    phone = models.CharField(max_length=10)
    ctime = models.DateTimeField(auto_now_add=True)


# 商品信息(已完成)
class goods_info(models.Model):
    img = models.ImageField(upload_to='image', null=True)
    goods_name = models.CharField(max_length=20)
    goods_price = models.IntegerField(default=0)
    goods_info = models.CharField(max_length=100)
    goods_number =models.CharField(max_length=100)
    create_time = models.DateTimeField(auto_now=True, null=True)


# 公告牌(未完成)
class Billboard(models.Model):
    billboard_name = models.CharField(max_length=200)
    billboard_content = models.CharField(max_length=100)
    billboard_time = models.DateTimeField(auto_now_add=True, null=True)
    billboard_auth = models.CharField(max_length=30)


# 购物车表(已完成)
class Cart(models.Model):
    c_user = models.ForeignKey(UserInfo, null=True, blank=True, on_delete=models.SET_NULL)
    c_goods = models.ForeignKey(goods_info, null=True, blank=True, on_delete=models.SET_NULL)
    c_goods_name = models.CharField(max_length=50, null=True)
    c_goods_price = models.IntegerField(default=0)
    c_goods_num = models.IntegerField(default=1)
    c_is_select = models.BooleanField(default=True)
# 订单表 与 用户  由多对一(已完成)
class Order(models.Model):
    o_user = models.ForeignKey(UserInfo, null=True, blank=True, on_delete=models.SET_NULL)
    o_price = models.FloatField(default=0)
    o_time = models.DateTimeField(auto_now=True)
    # 已下单为支付
    o_status = models.IntegerField(default=ORDER_STATUS_NOT_PAY)

# 订单商品(已完成)
class OrderGoods(models.Model):
    o_order = models.ForeignKey(Order, null=True, blank=True, on_delete=models.SET_NULL)
    o_goods = models.ForeignKey(goods_info, null=True, blank=True, on_delete=models.SET_NULL)
    o_goods_num=models.IntegerField(default=1)
